import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;

public class TestRedisForSpring {

    public static void main(String[] args) {
        //获取spring配置文件
        ApplicationContext ctx =new ClassPathXmlApplicationContext("applicationContext.xml");
        //实例化RedisTemplate,redisTemplate 为spring中配置的bean名称
        RedisTemplate tmp= (RedisTemplate)ctx.getBean("redisTemplate");
        //往redis中加入值
        tmp.opsForValue().set("key","hello world");
        //读取redis中的key
        System.out.println("***************"+tmp.opsForValue().get("key"));
    }
}
